package com.f.controller;

import com.f.bean.Emp;
import com.f.bean.EmpDept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class EmpController {
    @Autowired
    private RestTemplate restTemplate;
    // 走数据库，再走redis
    @RequestMapping("emp/{id}")
    public EmpDept getById(@PathVariable("id") Integer id){
        EmpDept empDept = restTemplate.getForObject("http://PROVIDER1/emp/id", EmpDept.class);
        return empDept;
    }
    // 直接走，es
    @RequestMapping("emp/by/{empName}")
    public List<Emp> getByName(@PathVariable("empName") String empName){
        List<Emp> list = restTemplate.getForObject("http://PROVIDER1/emp/by/{empName}", List.class);
        return list;

    }
}
